package ThreadDemo;
/*加上volatile解决ThreadDemo18中的线程安全问题*/
import java.util.Scanner;

class A19{
    volatile int a=0;
    public void increase(){
        a++;
    }
}

public class ThreadDemo19 {
    public static void main(String[] args) {
        A19 a19=new A19();
        Thread t1 = new Thread(){
            @Override
            public void run() {
                while(a19.a==0) {

                }
                System.out.println("循环结束");
            }
        };
        t1.start();
        Thread t2 = new Thread() {
            @Override
            public void run() {
                Scanner sc=new Scanner(System.in);
                System.out.println("请输入一个整数：");
                a19.a=sc.nextInt();
            }
        };
        t2.start();
    }
}